package thirdassigment;

import java.io.File;
//import java.io.FilenameFilter;
//import java.util.Scanner;

public class Find implements ICommandExecutor {
	//private static ICommandExecutor instance;
public void execute(String enterstr) {
	
	String[] str_mas = enterstr.split(" ");
	//String command = str_mas[0];
	String directory = str_mas[1];
    String SearchWord = str_mas[2];
    inner_execute(directory,SearchWord);
}
    
    private void inner_execute(String directory, String SearchWord){
	 
    File folder = new File(directory);
	    if(!folder.exists()){
	        System.out.println("Directory not found: " + directory);
	} else
  
    for (File f : folder.listFiles()) {
        if (f.getName().contains(SearchWord)) 
        	System.out.println(f.getName());
    }
}
private static Find instance;
private Find(){          
}
public static ICommandExecutor getInstance() {
    if(instance==null){
            instance=new Find();       
            }
    return instance;
}

}
